import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * Created by kzdatd on 2020/1/14.
 */
public class DataProducer {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.130.70:9092");
        props.put("acks", "all");
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        String val = "{\"时间\":\"2018/1/4 17:47:00\",\"加载吨位\":8183.8343,\"F12\":325.7796,\"P17_YL\":0.4381,\"电机转速\":500.0125}";
        while (true){
            try {
                producer.send(new ProducerRecord<String, String>("inputtopic", null, val));
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
